<?php  if ( ! defined('DLFMPATH')) exit('No direct script access allowed');

//include DLFMPATH . '/libraries/' . 'raintpl/rain.tpl.class.php';
include DLFMPATH . '/libraries/' . 'raintpl/RainTpl3beta.php';

class DL_View extends RainTPL{
    private $tpl_file;
    private $cache_lifetime;
    private $cache_directory;
    private $is_cache = FALSE;
    
    function __construct($folder  , $file , $ext)
    {
	$this->config_view($folder  , $file , $ext);
    }
    
    private function config_view($folder  , $file , $ext)
    {
	GLOBAL $config;
	$this->configure('base_url' , $config['base_url']);
	$this->configure('tpl_dir' , $folder);
	$this->configure('tpl_ext' , $ext);
	$this->configure('cache_dir' , $config['raintpl']['cache_dir'].'/');
	$this->tpl_file = $file;
	$this->cache_directory = $config['raintpl']['cache_dir'].'/';
	$this->cache_lifetime = $config['raintpl']['cache_lifetime'];
	
	$this->set_global($config);
    }
    
    private function set_global($config)
    {
	$this->assign('site_url',$config['base_url']);
    }
    
    public function set_cache($time=NULL)
    {
	$this->is_cache = TRUE;
	$time ? $this->cache_lifetime = $time : '';
    }
    
    public function clear_cache()
    {
	if( ! $this->is_cache){
	    array_map('unlink',glob($this->cache_directory."*.rtpl.php"));
	}
    }
    
    public function set_var($var,$val=NULL)
    {
	if(is_array($var)){
	    $this->assign($var);
	}else{
	    $this->assign($var,$val);
	}
    }
    
    public function display(){
	$this->draw($this->tpl_file);
	$this->clear_cache();
    }
    
    public function html(){
	$html = $this->draw($this->tpl_file,TRUE);
	$this->clear_cache();
	return $html;
    }
    
    public function write($filename , $folder=''){
	if($folder!=''){
	    $file = BASEPATH.'/'.$folder.'/'.$filename;
	}else{
	    $file = $this->root.$filename;
	}
	$this->parse($this->tpl_handle, 'file' , $file);
    }
}

/* End of file DL_View.class.php */
/* Location: ./core/DL_View.class.php */